3001. 捕获黑皇后需要的最少移动次数
为保证权益,题目请参考 3001. 捕获黑皇后需要的最少移动次数(From LeetCode).
解决方案1
Python
python
class Solution:
def minMovesToCaptureTheQueen(
self, a: int, b: int, c: int, d: int, e: int, f: int
) -> int:
# 车
if a == e and (
c != e
or (
c == e
and ((b < f and (d < b or d > f)) or (b > f and (d < f or d > b)))
)
):
return 1
if b == f and (
d != f
or (
d == f
and ((a < e and (c < a or c > e)) or (a > e and (c < e or c > a)))
)
):
return 1
if f - e == d - c and (
f - e != b - a
or ((c < e and (a < c or a > e)) or (c > e and (a < e or a > c)))
):
return 1
if f + e == d + c and (
f + e != b + a
or ((c < e and (a < c or a > e)) or (c > e and (a < e or a > c)))
):
return 1
return 2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36